package com.eboss2.sbs.http;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.widget.Toast;

import com.google.gson.reflect.TypeToken;
import com.mytools.tool.utils.DialogUtil;

public abstract class HttpCallback<T> {

	private Context context;

    private Dialog loadingDialog;
    
    private boolean isShowDialog = true;

    public HttpCallback(Activity context) {
        this.context = context;
        loadingDialog = DialogUtil.getLoadingDialg(context);
    }
    
    public HttpCallback(Activity context, boolean isShowDialog) {
        this.context = context;
        this.isShowDialog = isShowDialog;
        if(isShowDialog){loadingDialog = DialogUtil.getLoadingDialg(context);}
    }
    
    public HttpCallback(Context context) {
        this.context = context;
    }

    public void preLoad() {
    	//Log.e("666: ", loadingDialog!=null?"dialog is not null":"dialog is null");
        if(loadingDialog!=null){
        	loadingDialog.show();
        }
    }

    public void postLoad() {
    	try {
    		if(loadingDialog!=null){loadingDialog.dismiss();}
		} catch (Exception e) {
		}
      
    }

    public void onFailure(int code, String message) {
    	try {
    		if(loadingDialog!=null){loadingDialog.dismiss();}
		} catch (Exception e) {}
    	Toast.makeText(context, message, Toast.LENGTH_SHORT).show();
    }

    public abstract void onSuccess(int code, T data);

    public abstract TypeToken<T> getTypeToken();
}
